package com.mxd.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.mxd.entity.User;
import com.mxd.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author mxd
 * @since 2018-09-04
 */
@Api(description="用户管理")
@RestController
@RequestMapping("//user")
public class UserController {
	@Autowired
	UserService userService;
	
	@ApiOperation("主页")
	@RequestMapping(value="/index",method = RequestMethod.GET )
	public String index(){
		return "index";
	}
	//TODO Table 'news_system.nsuser' doesn't exist
	@ApiOperation("用户登录")
	@RequestMapping(value="/login",method = RequestMethod.GET )
	public String login(User user){
		if (userService.login(user)) {
			return "success";
		}
		return "fail";
	}
	
	@ApiOperation("用户注册")
	@PostMapping()
	public String register(User user){
		if (userService.insert(user)) {
			return "success";
		}
		return "fail";
	}
}
